import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILockModifyPasswordWindow } from "../../../../modules/interfaces/ILockModifyPasswordWindow";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { TextInput } from "../../../../fl/controls/TextInput";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { LockInfoData } from "./LockInfoData";
type int = number;
//class LockModifyPasswordWindow
    
    export  class LockModifyPasswordWindow extends BaseWindow implements ILockModifyPasswordWindow
    {
        constructor()
        {
            super();
            setSize(350, 290);
            title = Language.getString(35509);
            titleHeight = 30;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            var loc1=ObjCreate.createBg(18, 43, 315, 205, this);
            var loc2=ObjCreate.createTextField("", 75, 50, 200, 20, this);
            loc2.htmlText = Language.getString(35511);
            loc2.filters = [];
            var loc3=ObjCreate.createTextField("", 75, 110, 200, 20, this);
            loc3.htmlText = Language.getString(35512);
            loc3.filters = [];
            var loc4;
            (loc4 = ObjCreate.createTextField("", 75, 165, 200, 20, this)).htmlText = Language.getString(35513);
            loc4.filters = [];
            this._oldPwTxt = ObjCreate.createGTextInput(75, 75, 200, 25, this);
            this._oldPwTxt.maxChars = 9;
            this._oldPwTxt.restrict = "0-9";
            this._oldPwTxt.displayAsPassword = true;
            this._oldPwTxt.addEventListener(flash.events.FocusEvent.FOCUS_IN, this.onTextfieldFocusHandler);
            this._newPwTxt = ObjCreate.createGTextInput(75, 135, 200, 25, this);
            this._newPwTxt.maxChars = 9;
            this._newPwTxt.restrict = "0-9";
            this._newPwTxt.displayAsPassword = true;
            this._newPwTxt.addEventListener(flash.events.FocusEvent.FOCUS_IN, this.onTextfieldFocusHandler);
            this._newPwTwoTxt = ObjCreate.createGTextInput(75, 195, 200, 25, this);
            this._newPwTwoTxt.maxChars = 9;
            this._newPwTwoTxt.restrict = "0-9";
            this._newPwTwoTxt.displayAsPassword = true;
            this._newPwTwoTxt.addEventListener(flash.events.FocusEvent.FOCUS_IN, this.onTextfieldFocusHandler);
            this._focusInTxt = this._oldPwTxt;
            this._leftTimes = ObjCreate.createTextField("", 100, 228, 200, 20, this);
            this._leftTimes.htmlText = "<font color=\'#ff0000\'></font>";
            this._leftTimes.filters = [];
            var loc5;
            (loc5 = ObjCreate.createGButton(Language.getString(35227), 100, 253, 60, 25, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onSureBtnClickHandler);
            var loc6;
            (loc6 = ObjCreate.createGButton(Language.getString(35407), 200, 253, 60, 25, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            return;
        }

        /* internal  */onTextfieldFocusHandler(arg1: Object /* flash.events.FocusEvent */): void
        {
            this._focusInTxt = arg1.currentTarget as TextInput;
            return;
        }

        /* internal  */onSureBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this._newPwTxt.text != "") 
            {
                if (this._newPwTwoTxt.text != "") 
                {
                    if (this._newPwTxt.text == this._newPwTwoTxt.text) 
                    {
                        loc1 = [];
                        loc1.push(this._newPwTxt.text);
                        loc1.push(this._oldPwTxt.text);
                        Dispatcher.dispatchEvent(new DataEvent(EventName.LockModifyPassword, loc1));
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(35414));
                    }
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(35413));
                }
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(35412));
            }
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._oldPwTxt.text = "";
            this._newPwTxt.text = "";
            this._newPwTwoTxt.text = "";
            Dispatcher.dispatchEvent(new DataEvent(EventName.LockNumberKeyboardVisible, false));
            Dispatcher.removeEventListener(EventName.LockNumberKeyboardChange, this.onNumberKeyboardChangeHandler);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.setLeftTimes();
            Dispatcher.addEventListener(EventName.LockNumberKeyboardChange, this.onNumberKeyboardChangeHandler);
            return;
        }

        /* internal  */onNumberKeyboardChangeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as string;
            var loc2=this._focusInTxt.text.length;
            if (loc1 != "←") 
            {
                if (loc1 != "C") 
                {
                    this._focusInTxt.text = this._focusInTxt.text.concat(loc1);
                }
                else 
                {
                    this._focusInTxt.text = "";
                }
            }
            else 
            {
                this._focusInTxt.text = this._focusInTxt.text.slice(0, (loc2 - 1));
            }
            return;
        }

        public setLeftTimes(): void
        {
            if (LockInfoData.sPlayerLockError == null) 
            {
                return;
            }
            this._leftTimes.htmlText = Language.getStringByParam(35514, LockInfoData.sPlayerLockError.leftModifyTimes);
            return;
        }

        /* internal */ /* var */_oldPwTxt: TextInput;

        /* internal */ /* var */_newPwTxt: TextInput;

        /* internal */ /* var */_newPwTwoTxt: TextInput;

        /* internal */ /* var */_focusInTxt: TextInput;

        /* internal */ /* var */_leftTimes: Object /* flash.text.TextField */;
    }
